The present invention relates to a compiler for optimizing a program. In particular, the present invention relates to a compiler for optimizing an instruction to assign a value to a variable.
A programming language processor or an operating system includes a group of programs in which frequently used functions are gathered together. Such a program is termed as a library program. A library program starts to operate when called by a user program, and then returns the execution result as a return value to the user program.
The indexOf method of String class written in the Java (registered trademark) language, for example, searches a character string specified as an argument for a character specified as an argument, and then returns the index of the character (a numeric value indicating where the character is from the top of the character string, for example). When the character is not searched out, the indexOf method returns the numeric value −1 indicating that the character is not searched out.
Moreover, as another example, a method that generates an object satisfying a condition specified as an argument returns the pointer of the object in a case where the method succeeds in generating the object. On the other hand, if the method fails to generate the object, the method returns a constant NULL indicating that the generation of the object failed.
As described in the above examples, a return value has multiple properties in some cases. Specifically, the return value indicates not only the processing result such as an index, a pointer or the like, but also the success or failure of the processing by use of a specific numeric value such as −1 or NULL.
Incidentally, Japanese Patent Application Laid-open Publication No. 2003-196106 is a reference for various types of optimization methods as to an assignment instruction.
A returned numeric value is assigned to a variable, and then is to be referenced in processing thereafter. In a user program, for example, the variable is compared with a constant. Moreover, the variable may be used in an arithmetic operation. In some user programs, however, the variable is compared only with a specific constant value such as −1 or NULL, and is not used in a comparison with another variable or in an arithmetic operation. In this case, the processing to find a specific numeric value to be assigned to the variable, the value being, for example, an index or a pointer to an object, results in being useless.